import { NAV_IGORE } from "@/setting";
import { defineStore } from "pinia";

export const useNavStore = defineStore({
  id: "nav",
  state: () => ({
    visitedViews: [],
  }),
  actions: {
    addVisitedViews(data) {
      if (NAV_IGORE.some((v) => v == data.path)) return;
      if (this.visitedViews.some((v) => v.path === data.path)) return;
      this.visitedViews.push(
        Object.assign({}, data, {
          title: data.meta.title || "no-name",
        })
      );
    },
    delVisitedViews(data) {
      for (const [i, v] of this.visitedViews.entries()) {
        if (v.path === data.path) {
          this.visitedViews.splice(i, 1);
          break;
        }
      }
    },
    delAllVisitedViews() {
      this.visitedViews = [];
    },
  },
});
